﻿<frameworkControls:NavigatePhoneApplicationPage 
    x:Class="mal.WP7.GoogleAnalytics.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:converters="clr-namespace:mal.WP7.GoogleAnalytics.Converters" 
    xmlns:frameworkControls="clr-namespace:mal.WP7.Framework.Controls;assembly=mal.WP7.Framework"
    xmlns:tile="clr-namespace:mal.WP7.GoogleAnalytics.Business.Tiles;assembly=mal.WP7.GoogleAnalytics.Business"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:local="clr-namespace:mal.WP7.GoogleAnalytics"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="728" 
    d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="False">

    <phone:PhoneApplicationPage.Resources>
        <converters:StringToStringWithSeperatorConverter x:Key="StringToStringWithSeperatorConverter" />
        <converters:DoublePositiveToNegativeConverter x:Key="DoublePositiveToNegativeConverter" />

    </phone:PhoneApplicationPage.Resources>
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <local:HeaderBackground Grid.RowSpan="2" VerticalAlignment="Top" />


        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" 
                    Style="{StaticResource TitlePanelStyle}">
            <TextBlock x:Name="ApplicationTitle" Text="{Binding Text.ApplicationName, Source={StaticResource Resource}}" 
                       Style="{StaticResource PhoneTextNormalStyle}"/>

            <!--   <TextBlock x:Name="PageTitle" Text="{Binding Text.DashboardTitle, Source={StaticResource Resource}}"
                       Margin="9,-7,0,0" 
                       Style="{StaticResource PhoneTextTitle1Style}"/>-->
        </StackPanel>



        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <controls:Panorama ItemsSource="{Binding Items}"
                        Visibility="{Binding HasWebsites, Converter={StaticResource BoolToVisibilityConverter}}"
                        SelectionChanged="Panorama_SelectionChanged">
                <controls:Panorama.Background>
                    <ImageBrush ImageSource="PanoramaBackground.png"/>
                </controls:Panorama.Background>

                <controls:Panorama.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock x:Name="ApplicationTitle" Text="{Binding Label}" 
                       Style="{StaticResource PhoneTextTitle1Style}"/>
                    </DataTemplate>
                </controls:Panorama.HeaderTemplate>
                <controls:Panorama.ItemTemplate>
                    <DataTemplate>
                        <Grid HorizontalAlignment="Center" >                      
                                <StackPanel 
                                Visibility="{Binding IsLoading, Converter={StaticResource BoolToVisibilityConverter}}"
                                 Grid.RowSpan="2"
                                 VerticalAlignment="Center"
                                        HorizontalAlignment="Stretch">
                                    <ProgressBar Width="470"
                                    IsIndeterminate="True"  HorizontalAlignment="Stretch" />
                                    <TextBlock   HorizontalAlignment="Center"
                                    Style="{StaticResource PhoneTextSmallStyle}"
                                    Text="{Binding Text.HomePageLoadingData, Source={StaticResource Resource}}" />
                                </StackPanel>

                                <ListBox ItemsSource="{Binding Rows}"
                                     SelectedItem="{Binding SelectedRow, Mode=TwoWay}"
                                     Visibility="{Binding IsLoading
                                        , Converter={StaticResource BoolToVisibilityConverter},ConverterParameter=inverse}">
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <Grid Margin="5">

                                                <tile:WebsiteTile 
                                                NumberOfVisitors="{Binding CurrentValue}"
                                                Delta="{Binding ProgressPercent}" />

                                                <Canvas xmlns="http://schemas.microsoft.com/client/2007" 
                                                    
                                                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
                                                    <Canvas.Clip>
                                                        <RectangleGeometry Rect="7,7,159,159">
                                                        </RectangleGeometry>
                                                    </Canvas.Clip>
                                                    <Canvas.Triggers>
                                                        <EventTrigger RoutedEvent="Canvas.Loaded" >
                                                            <BeginStoryboard>
                                                                <Storyboard x:Name="animation" Storyboard.TargetProperty="(Canvas.Left)" RepeatBehavior="Forever" >
                                                                    <DoubleAnimation Storyboard.TargetName="ScrollText" From="0" 
                                                                                 To="{Binding ElementName=ScrollText,Path=ActualWidth, Converter={StaticResource DoublePositiveToNegativeConverter}}"
                                                                                 Duration="0:0:20"  />
                                                                    <DoubleAnimation Storyboard.TargetName="ScrollText1" From="{Binding ElementName=ScrollText1,Path=ActualWidth}" To="0" Duration="0:0:20"  />
                                                                </Storyboard>
                                                            </BeginStoryboard>
                                                        </EventTrigger>
                                                    </Canvas.Triggers>

                                                    <TextBlock x:Name="ScrollText" Text="{Binding WebsiteName, Converter={StaticResource StringToStringWithSeperatorConverter}}" Canvas.Top="138" FontSize="21" Padding="0,0,50,0">
                                                    </TextBlock>

                                                    <TextBlock x:Name="ScrollText1" Text="{Binding WebsiteName, Converter={StaticResource StringToStringWithSeperatorConverter}}" Canvas.Top="138" FontSize="21" Padding="0,0,50,0">
                                                    </TextBlock>

                                                    <!--<TextBlock x:Name="ScrollText1" Canvas.Top="140" FontSize="21" Padding="0,0,50,0" Text="{Binding WebsiteName}" />-->

                                                </Canvas>

                                                <!--<TextBlock Text="{Binding WebsiteName}"
                                                           Width="160"
                                                           Margin="8,0,8,5"
                                                           FontSize="21"
                                                           VerticalAlignment="Bottom" />-->
                                            </Grid>

                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                    <ListBox.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <toolkit:WrapPanel />
                                        </ItemsPanelTemplate>
                                    </ListBox.ItemsPanel>
                                </ListBox>
                        </Grid>
                    </DataTemplate>
                </controls:Panorama.ItemTemplate>
            </controls:Panorama>

            <StackPanel 
                                Visibility="{Binding IsLoading, Converter={StaticResource BoolToVisibilityConverter}}"
                                 Grid.RowSpan="2"
                                 VerticalAlignment="Center"
                                        HorizontalAlignment="Stretch">
                <ProgressBar Width="470"
                                    IsIndeterminate="True"  HorizontalAlignment="Stretch" />
                <TextBlock   HorizontalAlignment="Center"
                                    Style="{StaticResource PhoneTextSmallStyle}"
                                    Text="{Binding Text.HomePageAuthentication, Source={StaticResource Resource}}" />
            </StackPanel>
            
            <TextBlock  Style="{StaticResource PhoneTextLargeStyle}"
                        VerticalAlignment="Center"
                        HorizontalAlignment="Center"
                        Visibility="{Binding HasAccounts
                            , Converter={StaticResource BoolToVisibilityConverter}
                         , ConverterParameter=inverse}"
                        Text="{Binding Text.MainPageNoWebsite, Source={StaticResource Resource}}" />
        </Grid>


    </Grid>

    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <!--<shell:ApplicationBarIconButton IconUri="/Images/appbar.add.rest.png" Text="ajouter"/>-->
            <shell:ApplicationBarIconButton IconUri="/Images/appbar.feature.settings.rest.png" 
                                            Text="paramètres" 
                                            Click="OnApplicationBarIconButtonClick"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem x:Name="aboutButton"
                                          Text="about"
                                          Click="OnAboutButtonClick" />
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>
</frameworkControls:NavigatePhoneApplicationPage >